package com.xinzhi.service.impl;

import cn.hutool.core.util.StrUtil;
import com.xinzhi.mapper.BumentaiMapper;
import com.xinzhi.pojo.dto.Bumentai;
import com.xinzhi.pojo.dto.Mnhgty;
import com.xinzhi.service.BumentaiService;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BumentaiServiceImpl implements BumentaiService {
    @Autowired
    private BumentaiMapper bumentaiMapper;
    @Autowired
    private RedisUtils redisUtils;

    /**
     * 部门台账评分汇总根据成绩申述状态查询
     *
     * @param
     * @return
     */
    @Override
    public Result selectAll(String appeal_status) {
        if (appeal_status.equals("pending")){
            appeal_status="待审核";
        }
        if (appeal_status.equals("approved")){
            appeal_status="已审核通过";
        }
        if(appeal_status.equals("reviewed")){
            appeal_status="已审核退回";
        }
        String bumentai = (String) redisUtils.get("bumentai");
        if (StrUtil.isNotBlank(bumentai)) {
            return Result.ok(bumentai);
        }
        List<Bumentai> bumentais = bumentaiMapper.selectAll(appeal_status);
        if (bumentais.size() > 0) {
            return Result.ok(bumentais);
        } else {
            return Result.error("没有数据");
        }
    }


    /**
     * 部门台账评分汇总根据进展状态查询接口
     * @param statet
     * @return
     */
    @Override
    public Result selectbumenzhuangtai(String statet) {
        String o = (String) redisUtils.get("statet");
        if (StrUtil.isNotBlank(o)) {
            return Result.ok(o);
        }
            List<Bumentai> selectbumenzhuangtai = bumentaiMapper.selectbumenzhuangtai(statet);
            if (selectbumenzhuangtai == null) {
                return Result.error("数据不存在");
            }
            return Result.ok(selectbumenzhuangtai);
        }
    /**
     * 部门台账评分汇总查询接口
     * @return
     */

    @Override
    public Result selectbumen() {
        List<Mnhgty> bumentais = bumentaiMapper.selectAlls();
        return Result.ok(bumentais);
    }
}